package cn.lanqiao.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.SystemColor;

public class TeacherMainFrm extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
    JDesktopPane desktopPane=null;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TeacherMainFrm frame = new TeacherMainFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TeacherMainFrm() {
		setTitle("教务处管理系统");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 998, 577);
		
		JMenuBar JMenuBar = new JMenuBar();
		JMenuBar.setBackground(SystemColor.menu);
		setJMenuBar(JMenuBar);
		
		JMenu mnNewMenu = new JMenu("教师管理");
		mnNewMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
		mnNewMenu.setForeground(new Color(0, 0, 0));
		JMenuBar.add(mnNewMenu);
		
		JMenuItem menuItemSuroce = new JMenuItem("管理学生成绩");
		menuItemSuroce.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
		menuItemSuroce.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			String title="学生成绩";
			JInternalFrame[] childFrames=desktopPane.getAllFrames();
			boolean isExists=false;
			for(JInternalFrame f: childFrames) {
				if(f.getTitle().equals(title)) {
					try {
						f.setSelected(true);
						isExists=true;
					}catch (PropertyVetoException e1) {
						e1.printStackTrace();
					}
					break;
				}
			}
			if(!isExists) {
				TeacherSource source=new TeacherSource();
				source.setVisible(true);
				desktopPane.add(source);
			}
			}
			
		});
		menuItemSuroce.setForeground(Color.DARK_GRAY);
		mnNewMenu.add(menuItemSuroce);
		
		JMenuItem menuItemClass = new JMenuItem("管理选课名单");
		menuItemClass.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
		menuItemClass.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//弹出子窗体
				TeacherCourse addChildFrm=new TeacherCourse();
				addChildFrm.setVisible(true);
				desktopPane.add(addChildFrm);
			}
		});
		menuItemClass.setForeground(Color.DARK_GRAY);
		mnNewMenu.add(menuItemClass);
		
		JMenuItem menuItemId = new JMenuItem("退出当前账号");
		menuItemId.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
		menuItemId.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		menuItemId.setForeground(Color.DARK_GRAY);
		mnNewMenu.add(menuItemId);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(0, 0,0, 0));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		desktopPane = new JDesktopPane();
		desktopPane.setBorder(null);
		desktopPane.setBackground(Color.WHITE);
		contentPane.add(desktopPane, BorderLayout.CENTER);
		//居中
		TeacherMainFrm.this.setLocationRelativeTo(null);
	}
}
